﻿/* Author: Achim Schnell */

using AppFx.Tokenization;
using System;

namespace AppFx.Parsing
{
    /// <summary>
    /// Represents a parsed token being an operator.
    /// </summary>
    public class OperatorToken : ParsedToken
    {
        #region Properties

        /// <summary>
        /// Gets or sets the precedence of the operator.
        /// </summary>
        /// <value>
        /// The precedence.
        /// </value>
        public int Precedence { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the operator is left associative.
        /// </summary>
        /// <value>
        ///   <c>true</c> if the operator is left associative; otherwise, <c>false</c>.
        /// </value>
        public bool LeftAssociative { get; set; }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="OperatorToken"/> class.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="parsedType">Type of the parsed token.</param>
        public OperatorToken(IToken token, eParsedTokenType parsedType, int precedence, bool leftAssociative)
            : base(token, parsedType)
        {
            Precedence = precedence;
            LeftAssociative = leftAssociative;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return base.ToString() + String.Format(" P:{0}, LA:{1}", Precedence, LeftAssociative);
        }

        #endregion
    }
}
